package com.shelpe.services.sinbad.entity.jpa;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;

import com.shelpe.services.sinbad.entity.jpa.AdgroupSearchCrowd.AdgroupSearchCrowdPK;
import com.shelpe.services.sinbad.service.simbaproxy.UserClient;

import lombok.Data;

@Entity(name = "adgroup_search_crowds")
@IdClass(AdgroupSearchCrowdPK.class)
@Data
public class AdgroupSearchCrowd {

	@Id
	@Column(name = "crowd_id")
	private long crowdID;
	
	@Id
	@Column(name = "adgroup_id")
	private long adgroupID;
	
	@Column(name = "user_id")
	private long userID;
	@Column(name = "cust_id")
	private long custID; // 用户id
	@Column(name = "crowd_name")
	private String crowdName;
	@Column(name = "campaign_id")
	private long campaignID;
	@Column(name = "target_id")
	private long targetID;
	@Column(name = "template_id")
	private long templateID;
	@Column(name = "biz_type")
	private long bizType; // 业务类型
	private int type; // 人群类型
	@Column(name = "fit_discount")
	private int fitDiscount;

	@Column(name = "create_time")
	private Date createTime;
	@Column(name = "updated_time")
	private Date updatedTime;
	
	@Data
	public static class AdgroupSearchCrowdPK implements Serializable {
		private static final long serialVersionUID = 1L;
		@Column(name = "crowd_id")
		private long crowdID;
		@Column(name = "adgroup_id")
		private long adgroupID;
	}

	public void from(UserClient.SearchCrowdDto dto, Adgroup adgroup) {
		this.setAdgroupID(adgroup.getAutoID());
		this.setCampaignID(adgroup.getCampaignID());
		this.setUserID(adgroup.getUserID());
		this.setUpdatedTime(new Date());
		this.setCreateTime(new Date());
		if (dto != null && dto.getCrowds() != null) {
			this.setBizType(dto.getCrowds().getBussiessType());
			this.setCrowdID(dto.getCrowds().getCrowdID());
			this.setCrowdName(dto.getCrowds().getName());
			this.setFitDiscount(dto.getCrowds().getFitDiscount());
			this.setTargetID(dto.getTargetID());
			this.setType(dto.getCrowds().getType());
			this.setCustID(dto.getCrowds().getCustID());
		}
	}
}
